//
//  TKYAddPicButton.m
//  ProgressReportProject
//
//  Created by apple on 2018/4/23.
//  Copyright © 2018年 铁科院. All rights reserved.
//

#import "TKYAddPicButton.h"

@implementation TKYAddPicButton
- (instancetype)initWithFrame:(CGRect)frame addPicTitleText:(NSString *)addPicTitleText addPicButtonTitle:(NSString *)addPicButtonTitle{
    if (self = [super initWithFrame:frame]) {
        self.frame = frame;
        [self initWithaddPicTitleText:addPicTitleText addPicButtonTitle:addPicButtonTitle];
    }
    return self;
}

- (void)initWithaddPicTitleText:(NSString *)addPicTitleText addPicButtonTitle:(NSString *)addPicButtonTitle{
    // UIView *superView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.kx_width, self.kx_height)];
    UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(kWidthScale *20, 10, 0, 0)];
    titleLabel.text = addPicTitleText;
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.font = [UIFont systemFontOfSize:14];
    [titleLabel sizeToFit];
    [self addSubview:titleLabel];
    
    UIButton *addPicBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    addPicBtn.frame = CGRectMake(kScreenWidth -kWidthScale *100, 0, kWidthScale *100, kWidthScale *40);
    [addPicBtn setTitle:addPicButtonTitle forState:UIControlStateNormal];
    [addPicBtn setImage:[UIImage imageNamed:@"add_photo"] forState:UIControlStateNormal];
    [addPicBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [addPicBtn addTarget:self action:@selector(addpicAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:addPicBtn];
}

- (void)addpicAction:(UIButton *)button{
    if (self.addPicButtonBlock) {
        self.addPicButtonBlock(button);
    }
}

//计算文本的宽度
- (CGFloat )sizeWidth:(NSString *)text{
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObject:[UIFont systemFontOfSize:17] forKey:NSFontAttributeName];
    CGFloat widthSize = [text boundingRectWithSize:CGSizeMake(MAXFLOAT, 0.0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size.width;
    
    return widthSize;
}

@end
